package com.boot2523.service;

import com.boot2523.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserRedisS {
    @Autowired
    public RedisTemplate<String,Object> redisTemplate;

    /**
     * 将对象保存在redis中
     * @param u
     */
    public void save(User u){
        redisTemplate.opsForValue().set(String.valueOf(u.getUid()),u);
    }

    /**
     * 根据键取值
     * @param key
     * @return
     */
    public Object get(String key){
        return redisTemplate.opsForValue().get(key);

    }
    public void delete(String key){
        redisTemplate.delete(key);
    }
    public List<Object> find(String key){
        return redisTemplate.opsForList().range(key,0,-1);
    }
}
